<!DOCTYPE html>
<html>
<!--
Copyright 2008 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by an Apache 2.0 License.
See the COPYING file for details.
-->
<!--

  @author nicksantos@google.com (Nick Santos)
-->
<head>
<title>Closure Unit Tests - goog.ui.Menu</title>
<style type='text/css'>
.goog-menu {
  position: absolute;
  color: #aaa;
}
</style>    
<script src="../base.js"></script>
<script>
  goog.require('goog.dom');
  goog.require('goog.events');
  goog.require('goog.events.Event');
  goog.require('goog.testing.events');
  goog.require('goog.testing.jsunit');
  goog.require('goog.ui.Menu');
</script>
</head>
<body>
<script>

var menu;
var clonedMenuDom;
    
function setUp() {
  clonedMenuDom = goog.dom.getElement('demoMenu').cloneNode(true);
  
  menu = new goog.ui.Menu();
}

function tearDown() {
  menu.dispose();

  var element = goog.dom.getElement('demoMenu');
  element.parentNode.replaceChild(clonedMenuDom, element);
}

function testHoverBehavior() {
  menu.decorate(goog.dom.getElement('demoMenu'));

  goog.testing.events.fireMouseOverEvent(goog.dom.getElement('menuItem2'),
      document.body);
  assertEquals(1, menu.getHighlightedIndex());

  menu.exitDocument();
  assertEquals(-1, menu.getHighlightedIndex());
}

function testIndirectionDecoration() {
  menu.decorate(goog.dom.getElement('complexMenu'));
  
  goog.testing.events.fireMouseOverEvent(goog.dom.getElement('complexItem3'),
      document.body);
  assertEquals(2, menu.getHighlightedIndex());
  
  menu.exitDocument();
  assertEquals(-1, menu.getHighlightedIndex());
}

</script>

<p>
  Here's a menu defined in markup:
</p>
<div id="demoMenu" class="goog-menu">
  <div id='menuItem1' class="goog-menuitem">Annual Report.pdf</div>
  <div id='menuItem2' class="goog-menuitem">Quarterly Update.pdf</div>
  <div id='menuItem3' class="goog-menuitem">Enemies List.txt</div>
</div>

<p>
  Here's a menu which has been rendered with an explicit content node:
</p>
<div id="complexMenu" class="goog-menu">
  <div style="border:1px solid black;">
    <div class="goog-menu-content">
      <div id='complexItem1' class="goog-menuitem">Drizzle</div>
      <div id='complexItem2' class="goog-menuitem">Rain</div>
      <div id='complexItem3' class="goog-menuitem">Deluge</div>
    </div>
  </div>
</div>

</body>
</html>
